<?php

/**
 * TransferScheduleApi
 * PHP version 8.3.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * The Selling Partner API for Amazon Seller Wallet Open Banking API.
 *
 * The Selling Partner API for Seller Wallet (Seller Wallet API) provides financial information that is relevant to a seller's Seller Wallet account. You can obtain financial events, balances, and transfer schedules for Seller Wallet accounts. You can also schedule and initiate transactions.
 *
 * The version of the OpenAPI document: 2024-03-01
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Api\sellerWallet\v2024_03_01;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use SpApi\ApiException;
use SpApi\AuthAndAuth\RestrictedDataTokenSigner;
use SpApi\Configuration;
use SpApi\HeaderSelector;
use SpApi\Model\sellerWallet\v2024_03_01\DeleteTransferSchedule;
use SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule;
use SpApi\Model\sellerWallet\v2024_03_01\TransferScheduleListing;
use SpApi\Model\sellerWallet\v2024_03_01\TransferScheduleRequest;
use SpApi\ObjectSerializer;
use Symfony\Component\RateLimiter\LimiterInterface;
use Symfony\Component\RateLimiter\RateLimiterFactory;
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;

/**
 * TransferScheduleApi Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */
class TransferScheduleApi
{
    public ?LimiterInterface $createTransferScheduleRateLimiter;
    public ?LimiterInterface $deleteScheduleTransactionRateLimiter;
    public ?LimiterInterface $getTransferScheduleRateLimiter;
    public ?LimiterInterface $listTransferSchedulesRateLimiter;
    public ?LimiterInterface $updateTransferScheduleRateLimiter;
    protected ClientInterface $client;

    protected Configuration $config;

    protected HeaderSelector $headerSelector;

    /**
     * @var int Host index
     */
    protected int $hostIndex;

    private bool $rateLimiterEnabled;
    private InMemoryStorage $rateLimitStorage;

    /**
     * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
     */
    public function __construct(
        Configuration $config,
        ?ClientInterface $client = null,
        ?bool $rateLimiterEnabled = true,
        ?HeaderSelector $selector = null,
        int $hostIndex = 0
    ) {
        $this->config = $config;
        $this->rateLimiterEnabled = $rateLimiterEnabled;

        if ($rateLimiterEnabled) {
            $this->rateLimitStorage = new InMemoryStorage();

            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('TransferScheduleApi-createTransferSchedule'), $this->rateLimitStorage);
            $this->createTransferScheduleRateLimiter = $factory->create('TransferScheduleApi-createTransferSchedule');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('TransferScheduleApi-deleteScheduleTransaction'), $this->rateLimitStorage);
            $this->deleteScheduleTransactionRateLimiter = $factory->create('TransferScheduleApi-deleteScheduleTransaction');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('TransferScheduleApi-getTransferSchedule'), $this->rateLimitStorage);
            $this->getTransferScheduleRateLimiter = $factory->create('TransferScheduleApi-getTransferSchedule');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('TransferScheduleApi-listTransferSchedules'), $this->rateLimitStorage);
            $this->listTransferSchedulesRateLimiter = $factory->create('TransferScheduleApi-listTransferSchedules');
            $factory = new RateLimiterFactory(Configuration::getRateLimitOptions('TransferScheduleApi-updateTransferSchedule'), $this->rateLimitStorage);
            $this->updateTransferScheduleRateLimiter = $factory->create('TransferScheduleApi-updateTransferSchedule');
        }

        $this->client = $client ?: new Client();
        $this->headerSelector = $selector ?: new HeaderSelector();
        $this->hostIndex = $hostIndex;
    }

    /**
     * Set the host index.
     *
     * @param int $hostIndex Host index (required)
     */
    public function setHostIndex(int $hostIndex): void
    {
        $this->hostIndex = $hostIndex;
    }

    /**
     * Get the host index.
     *
     * @return int Host index
     */
    public function getHostIndex(): int
    {
        return $this->hostIndex;
    }

    public function getConfig(): Configuration
    {
        return $this->config;
    }

    /**
     * Operation createTransferSchedule.
     *
     * Create a transfer schedule request from Amazon SW account to another customer provided account
     *
     * @param string                  $dest_account_digital_signature
     *                                                                Digital signature for the destination bank account details. (required)
     * @param string                  $amount_digital_signature
     *                                                                Digital signature for the source currency transaction amount. (required)
     * @param TransferScheduleRequest $body
     *                                                                Defines the actual payload of the request (required)
     * @param null|string             $restrictedDataToken            Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createTransferSchedule(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferScheduleRequest $body,
        ?string $restrictedDataToken = null
    ): TransferSchedule {
        list($response) = $this->createTransferScheduleWithHttpInfo($dest_account_digital_signature, $amount_digital_signature, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation createTransferScheduleWithHttpInfo.
     *
     * Create a transfer schedule request from Amazon SW account to another customer provided account
     *
     * @param string                  $dest_account_digital_signature
     *                                                                Digital signature for the destination bank account details. (required)
     * @param string                  $amount_digital_signature
     *                                                                Digital signature for the source currency transaction amount. (required)
     * @param TransferScheduleRequest $body
     *                                                                Defines the actual payload of the request (required)
     * @param null|string             $restrictedDataToken            Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function createTransferScheduleWithHttpInfo(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferScheduleRequest $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->createTransferScheduleRequest($dest_account_digital_signature, $amount_digital_signature, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-createTransferSchedule');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->createTransferScheduleRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\sellerWallet\v2024_03_01\ErrorList',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation createTransferScheduleAsync.
     *
     * Create a transfer schedule request from Amazon SW account to another customer provided account
     *
     * @param string                  $dest_account_digital_signature
     *                                                                Digital signature for the destination bank account details. (required)
     * @param string                  $amount_digital_signature
     *                                                                Digital signature for the source currency transaction amount. (required)
     * @param TransferScheduleRequest $body
     *                                                                Defines the actual payload of the request (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createTransferScheduleAsync(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferScheduleRequest $body
    ): PromiseInterface {
        return $this->createTransferScheduleAsyncWithHttpInfo($dest_account_digital_signature, $amount_digital_signature, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation createTransferScheduleAsyncWithHttpInfo.
     *
     * Create a transfer schedule request from Amazon SW account to another customer provided account
     *
     * @param string                  $dest_account_digital_signature
     *                                                                Digital signature for the destination bank account details. (required)
     * @param string                  $amount_digital_signature
     *                                                                Digital signature for the source currency transaction amount. (required)
     * @param TransferScheduleRequest $body
     *                                                                Defines the actual payload of the request (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createTransferScheduleAsyncWithHttpInfo(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferScheduleRequest $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule';
        $request = $this->createTransferScheduleRequest($dest_account_digital_signature, $amount_digital_signature, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-createTransferSchedule');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->createTransferScheduleRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'createTransferSchedule'.
     *
     * @param string                  $dest_account_digital_signature
     *                                                                Digital signature for the destination bank account details. (required)
     * @param string                  $amount_digital_signature
     *                                                                Digital signature for the source currency transaction amount. (required)
     * @param TransferScheduleRequest $body
     *                                                                Defines the actual payload of the request (required)
     *
     * @throws \InvalidArgumentException
     */
    public function createTransferScheduleRequest(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferScheduleRequest $body
    ): Request {
        // verify the required parameter 'dest_account_digital_signature' is set
        if (null === $dest_account_digital_signature || (is_array($dest_account_digital_signature) && 0 === count($dest_account_digital_signature))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $dest_account_digital_signature when calling createTransferSchedule'
            );
        }
        // verify the required parameter 'amount_digital_signature' is set
        if (null === $amount_digital_signature || (is_array($amount_digital_signature) && 0 === count($amount_digital_signature))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amount_digital_signature when calling createTransferSchedule'
            );
        }
        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling createTransferSchedule'
            );
        }

        $resourcePath = '/finances/transfers/wallet/2024-03-01/transferSchedules';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if (null !== $dest_account_digital_signature) {
            $headerParams['destAccountDigitalSignature'] = ObjectSerializer::toHeaderValue($dest_account_digital_signature);
        }
        // header params
        if (null !== $amount_digital_signature) {
            $headerParams['amountDigitalSignature'] = ObjectSerializer::toHeaderValue($amount_digital_signature);
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'POST',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation deleteScheduleTransaction.
     *
     * Delete a transaction request that is scheduled from Amazon SW account to another customer provided account
     *
     * @param string      $transfer_schedule_id
     *                                          A unique reference id for a scheduled transfer (required)
     * @param null|string $restrictedDataToken  Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function deleteScheduleTransaction(
        string $transfer_schedule_id,
        ?string $restrictedDataToken = null
    ): DeleteTransferSchedule {
        list($response) = $this->deleteScheduleTransactionWithHttpInfo($transfer_schedule_id, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation deleteScheduleTransactionWithHttpInfo.
     *
     * Delete a transaction request that is scheduled from Amazon SW account to another customer provided account
     *
     * @param string      $transfer_schedule_id
     *                                          A unique reference id for a scheduled transfer (required)
     * @param null|string $restrictedDataToken  Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\sellerWallet\v2024_03_01\DeleteTransferSchedule, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function deleteScheduleTransactionWithHttpInfo(
        string $transfer_schedule_id,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->deleteScheduleTransactionRequest($transfer_schedule_id);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-deleteScheduleTransaction');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->deleteScheduleTransactionRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\sellerWallet\v2024_03_01\DeleteTransferSchedule' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\sellerWallet\v2024_03_01\DeleteTransferSchedule' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\sellerWallet\v2024_03_01\DeleteTransferSchedule', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\sellerWallet\v2024_03_01\ErrorList',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation deleteScheduleTransactionAsync.
     *
     * Delete a transaction request that is scheduled from Amazon SW account to another customer provided account
     *
     * @param string $transfer_schedule_id
     *                                     A unique reference id for a scheduled transfer (required)
     *
     * @throws \InvalidArgumentException
     */
    public function deleteScheduleTransactionAsync(
        string $transfer_schedule_id
    ): PromiseInterface {
        return $this->deleteScheduleTransactionAsyncWithHttpInfo($transfer_schedule_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation deleteScheduleTransactionAsyncWithHttpInfo.
     *
     * Delete a transaction request that is scheduled from Amazon SW account to another customer provided account
     *
     * @param string $transfer_schedule_id
     *                                     A unique reference id for a scheduled transfer (required)
     *
     * @throws \InvalidArgumentException
     */
    public function deleteScheduleTransactionAsyncWithHttpInfo(
        string $transfer_schedule_id,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\sellerWallet\v2024_03_01\DeleteTransferSchedule';
        $request = $this->deleteScheduleTransactionRequest($transfer_schedule_id);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-deleteScheduleTransaction');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->deleteScheduleTransactionRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'deleteScheduleTransaction'.
     *
     * @param string $transfer_schedule_id
     *                                     A unique reference id for a scheduled transfer (required)
     *
     * @throws \InvalidArgumentException
     */
    public function deleteScheduleTransactionRequest(
        string $transfer_schedule_id
    ): Request {
        // verify the required parameter 'transfer_schedule_id' is set
        if (null === $transfer_schedule_id || (is_array($transfer_schedule_id) && 0 === count($transfer_schedule_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $transfer_schedule_id when calling deleteScheduleTransaction'
            );
        }

        $resourcePath = '/finances/transfers/wallet/2024-03-01/transferSchedules';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // path params
        if (null !== $transfer_schedule_id) {
            $resourcePath = str_replace(
                '{transferScheduleId}',
                ObjectSerializer::toPathValue($transfer_schedule_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            '',
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'DELETE',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getTransferSchedule.
     *
     * Find particular Amazon SW account transfer schedule by Amazon transfer schedule identifier
     *
     * @param string      $transfer_schedule_id
     *                                          Schedule ID of the Amazon SW transfer (required)
     * @param null|string $restrictedDataToken  Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function getTransferSchedule(
        string $transfer_schedule_id,
        ?string $restrictedDataToken = null
    ): TransferSchedule {
        list($response) = $this->getTransferScheduleWithHttpInfo($transfer_schedule_id, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation getTransferScheduleWithHttpInfo.
     *
     * Find particular Amazon SW account transfer schedule by Amazon transfer schedule identifier
     *
     * @param string      $transfer_schedule_id
     *                                          Schedule ID of the Amazon SW transfer (required)
     * @param null|string $restrictedDataToken  Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function getTransferScheduleWithHttpInfo(
        string $transfer_schedule_id,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->getTransferScheduleRequest($transfer_schedule_id);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-getTransferSchedule');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->getTransferScheduleRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\sellerWallet\v2024_03_01\ErrorList',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation getTransferScheduleAsync.
     *
     * Find particular Amazon SW account transfer schedule by Amazon transfer schedule identifier
     *
     * @param string $transfer_schedule_id
     *                                     Schedule ID of the Amazon SW transfer (required)
     *
     * @throws \InvalidArgumentException
     */
    public function getTransferScheduleAsync(
        string $transfer_schedule_id
    ): PromiseInterface {
        return $this->getTransferScheduleAsyncWithHttpInfo($transfer_schedule_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation getTransferScheduleAsyncWithHttpInfo.
     *
     * Find particular Amazon SW account transfer schedule by Amazon transfer schedule identifier
     *
     * @param string $transfer_schedule_id
     *                                     Schedule ID of the Amazon SW transfer (required)
     *
     * @throws \InvalidArgumentException
     */
    public function getTransferScheduleAsyncWithHttpInfo(
        string $transfer_schedule_id,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule';
        $request = $this->getTransferScheduleRequest($transfer_schedule_id);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-getTransferSchedule');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->getTransferScheduleRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'getTransferSchedule'.
     *
     * @param string $transfer_schedule_id
     *                                     Schedule ID of the Amazon SW transfer (required)
     *
     * @throws \InvalidArgumentException
     */
    public function getTransferScheduleRequest(
        string $transfer_schedule_id
    ): Request {
        // verify the required parameter 'transfer_schedule_id' is set
        if (null === $transfer_schedule_id || (is_array($transfer_schedule_id) && 0 === count($transfer_schedule_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $transfer_schedule_id when calling getTransferSchedule'
            );
        }

        $resourcePath = '/finances/transfers/wallet/2024-03-01/transferSchedules/{transferScheduleId}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // path params
        if (null !== $transfer_schedule_id) {
            $resourcePath = str_replace(
                '{transferScheduleId}',
                ObjectSerializer::toPathValue($transfer_schedule_id),
                $resourcePath
            );
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            '',
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'GET',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation listTransferSchedules.
     *
     * The API will return all the transfer schedules for a given Amazon SW account
     *
     * @param string      $account_id
     *                                         ID of the Amazon SW account (required)
     * @param null|string $next_page_token
     *                                         Pagination token to retrieve a specific page of results. (optional)
     * @param null|string $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function listTransferSchedules(
        string $account_id,
        ?string $next_page_token = null,
        ?string $restrictedDataToken = null
    ): TransferScheduleListing {
        list($response) = $this->listTransferSchedulesWithHttpInfo($account_id, $next_page_token, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation listTransferSchedulesWithHttpInfo.
     *
     * The API will return all the transfer schedules for a given Amazon SW account
     *
     * @param string      $account_id
     *                                         ID of the Amazon SW account (required)
     * @param null|string $next_page_token
     *                                         Pagination token to retrieve a specific page of results. (optional)
     * @param null|string $restrictedDataToken Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\sellerWallet\v2024_03_01\TransferScheduleListing, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function listTransferSchedulesWithHttpInfo(
        string $account_id,
        ?string $next_page_token = null,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->listTransferSchedulesRequest($account_id, $next_page_token);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-listTransferSchedules');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->listTransferSchedulesRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\sellerWallet\v2024_03_01\TransferScheduleListing' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\sellerWallet\v2024_03_01\TransferScheduleListing' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\sellerWallet\v2024_03_01\TransferScheduleListing', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\sellerWallet\v2024_03_01\ErrorList',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation listTransferSchedulesAsync.
     *
     * The API will return all the transfer schedules for a given Amazon SW account
     *
     * @param string      $account_id
     *                                     ID of the Amazon SW account (required)
     * @param null|string $next_page_token
     *                                     Pagination token to retrieve a specific page of results. (optional)
     *
     * @throws \InvalidArgumentException
     */
    public function listTransferSchedulesAsync(
        string $account_id,
        ?string $next_page_token = null
    ): PromiseInterface {
        return $this->listTransferSchedulesAsyncWithHttpInfo($account_id, $next_page_token)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation listTransferSchedulesAsyncWithHttpInfo.
     *
     * The API will return all the transfer schedules for a given Amazon SW account
     *
     * @param string      $account_id
     *                                     ID of the Amazon SW account (required)
     * @param null|string $next_page_token
     *                                     Pagination token to retrieve a specific page of results. (optional)
     *
     * @throws \InvalidArgumentException
     */
    public function listTransferSchedulesAsyncWithHttpInfo(
        string $account_id,
        ?string $next_page_token = null,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\sellerWallet\v2024_03_01\TransferScheduleListing';
        $request = $this->listTransferSchedulesRequest($account_id, $next_page_token);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-listTransferSchedules');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->listTransferSchedulesRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'listTransferSchedules'.
     *
     * @param string      $account_id
     *                                     ID of the Amazon SW account (required)
     * @param null|string $next_page_token
     *                                     Pagination token to retrieve a specific page of results. (optional)
     *
     * @throws \InvalidArgumentException
     */
    public function listTransferSchedulesRequest(
        string $account_id,
        ?string $next_page_token = null
    ): Request {
        // verify the required parameter 'account_id' is set
        if (null === $account_id || (is_array($account_id) && 0 === count($account_id))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $account_id when calling listTransferSchedules'
            );
        }

        $resourcePath = '/finances/transfers/wallet/2024-03-01/transferSchedules';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $account_id,
            'accountId', // param base name
            'string', // openApiType
            '', // style
            false, // explode
            true, // required
            $this->config
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $next_page_token,
            'nextPageToken', // param base name
            'string', // openApiType
            '', // style
            false, // explode
            false, // required
            $this->config
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            '',
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'GET',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation updateTransferSchedule.
     *
     * Update a transfer schedule information. Only fields (i.e; transferScheduleInformation, paymentPreference, transferScheduleStatus) in the request body can be updated.
     *
     * @param string           $dest_account_digital_signature
     *                                                         Digital signature for the destination bank account details. (required)
     * @param string           $amount_digital_signature
     *                                                         Digital signature for the source currency transaction amount. (required)
     * @param TransferSchedule $body
     *                                                         Defines the actual payload of the scheduled transfer request that is to be updated. (required)
     * @param null|string      $restrictedDataToken            Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function updateTransferSchedule(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferSchedule $body,
        ?string $restrictedDataToken = null
    ): TransferSchedule {
        list($response) = $this->updateTransferScheduleWithHttpInfo($dest_account_digital_signature, $amount_digital_signature, $body, $restrictedDataToken);

        return $response;
    }

    /**
     * Operation updateTransferScheduleWithHttpInfo.
     *
     * Update a transfer schedule information. Only fields (i.e; transferScheduleInformation, paymentPreference, transferScheduleStatus) in the request body can be updated.
     *
     * @param string           $dest_account_digital_signature
     *                                                         Digital signature for the destination bank account details. (required)
     * @param string           $amount_digital_signature
     *                                                         Digital signature for the source currency transaction amount. (required)
     * @param TransferSchedule $body
     *                                                         Defines the actual payload of the scheduled transfer request that is to be updated. (required)
     * @param null|string      $restrictedDataToken            Restricted Data Token (RDT) for accessing restricted resources (optional, required for operations that return PII)
     *
     * @return array of \SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule, HTTP status code, HTTP response headers (array of strings)
     *
     * @throws ApiException              on non-2xx response
     * @throws \InvalidArgumentException
     */
    public function updateTransferScheduleWithHttpInfo(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferSchedule $body,
        ?string $restrictedDataToken = null
    ): array {
        $request = $this->updateTransferScheduleRequest($dest_account_digital_signature, $amount_digital_signature, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-updateTransferSchedule');
        } else {
            $request = $this->config->sign($request);
        }

        try {
            $options = $this->createHttpClientOption();

            try {
                if ($this->rateLimiterEnabled) {
                    $this->updateTransferScheduleRateLimiter->consume()->ensureAccepted();
                }
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getResponse()->getBody()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            if ('\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule' === '\SplFileObject') {
                $content = $response->getBody(); // stream goes to serializer
            } else {
                $content = (string) $response->getBody();
                if ('\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule' !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, '\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule', []),
                $response->getStatusCode(),
                $response->getHeaders(),
            ];
        } catch (ApiException $e) {
            $data = ObjectSerializer::deserialize(
                $e->getResponseBody(),
                '\SpApi\Model\sellerWallet\v2024_03_01\ErrorList',
                $e->getResponseHeaders()
            );
            $e->setResponseObject($data);

            throw $e;
        }
    }

    /**
     * Operation updateTransferScheduleAsync.
     *
     * Update a transfer schedule information. Only fields (i.e; transferScheduleInformation, paymentPreference, transferScheduleStatus) in the request body can be updated.
     *
     * @param string           $dest_account_digital_signature
     *                                                         Digital signature for the destination bank account details. (required)
     * @param string           $amount_digital_signature
     *                                                         Digital signature for the source currency transaction amount. (required)
     * @param TransferSchedule $body
     *                                                         Defines the actual payload of the scheduled transfer request that is to be updated. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function updateTransferScheduleAsync(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferSchedule $body
    ): PromiseInterface {
        return $this->updateTransferScheduleAsyncWithHttpInfo($dest_account_digital_signature, $amount_digital_signature, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            )
        ;
    }

    /**
     * Operation updateTransferScheduleAsyncWithHttpInfo.
     *
     * Update a transfer schedule information. Only fields (i.e; transferScheduleInformation, paymentPreference, transferScheduleStatus) in the request body can be updated.
     *
     * @param string           $dest_account_digital_signature
     *                                                         Digital signature for the destination bank account details. (required)
     * @param string           $amount_digital_signature
     *                                                         Digital signature for the source currency transaction amount. (required)
     * @param TransferSchedule $body
     *                                                         Defines the actual payload of the scheduled transfer request that is to be updated. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function updateTransferScheduleAsyncWithHttpInfo(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferSchedule $body,
        ?string $restrictedDataToken = null
    ): PromiseInterface {
        $returnType = '\SpApi\Model\sellerWallet\v2024_03_01\TransferSchedule';
        $request = $this->updateTransferScheduleRequest($dest_account_digital_signature, $amount_digital_signature, $body);
        if (null !== $restrictedDataToken) {
            $request = RestrictedDataTokenSigner::sign($request, $restrictedDataToken, 'TransferScheduleApi-updateTransferSchedule');
        } else {
            $request = $this->config->sign($request);
        }
        if ($this->rateLimiterEnabled) {
            $this->updateTransferScheduleRateLimiter->consume()->ensureAccepted();
        }

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ('\SplFileObject' === $returnType) {
                        $content = $response->getBody(); // stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        if ('string' !== $returnType) {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();

                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        (string) $response->getBody()
                    );
                }
            )
        ;
    }

    /**
     * Create request for operation 'updateTransferSchedule'.
     *
     * @param string           $dest_account_digital_signature
     *                                                         Digital signature for the destination bank account details. (required)
     * @param string           $amount_digital_signature
     *                                                         Digital signature for the source currency transaction amount. (required)
     * @param TransferSchedule $body
     *                                                         Defines the actual payload of the scheduled transfer request that is to be updated. (required)
     *
     * @throws \InvalidArgumentException
     */
    public function updateTransferScheduleRequest(
        string $dest_account_digital_signature,
        string $amount_digital_signature,
        TransferSchedule $body
    ): Request {
        // verify the required parameter 'dest_account_digital_signature' is set
        if (null === $dest_account_digital_signature || (is_array($dest_account_digital_signature) && 0 === count($dest_account_digital_signature))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $dest_account_digital_signature when calling updateTransferSchedule'
            );
        }
        // verify the required parameter 'amount_digital_signature' is set
        if (null === $amount_digital_signature || (is_array($amount_digital_signature) && 0 === count($amount_digital_signature))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amount_digital_signature when calling updateTransferSchedule'
            );
        }
        // verify the required parameter 'body' is set
        if (null === $body || (is_array($body) && 0 === count($body))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $body when calling updateTransferSchedule'
            );
        }

        $resourcePath = '/finances/transfers/wallet/2024-03-01/transferSchedules';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if (null !== $dest_account_digital_signature) {
            $headerParams['destAccountDigitalSignature'] = ObjectSerializer::toHeaderValue($dest_account_digital_signature);
        }
        // header params
        if (null !== $amount_digital_signature) {
            $headerParams['amountDigitalSignature'] = ObjectSerializer::toHeaderValue($amount_digital_signature);
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            'application/json',
            $multipart
        );

        // for model (json/xml)
        if (isset($body)) {
            if ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body));
            } else {
                $httpBody = $body;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif ('application/json' === $headers['Content-Type']) {
                $httpBody = \GuzzleHttp\json_encode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams, $this->config);
            }
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = ObjectSerializer::buildQuery($queryParams, $this->config);

        return new Request(
            'PUT',
            $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option.
     *
     * @return array of http client options
     *
     * @throws \RuntimeException on file opening failure
     */
    protected function createHttpClientOption(): array
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: '.$this->config->getDebugFile());
            }
        }

        return $options;
    }
}
